import { useUserStore } from '@/store/index.js'
import { defineStore } from 'pinia'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    accessToken: undefined,
  }),
  actions: {
    setToken({ accessToken }) {
      this.accessToken = accessToken
    },
    resetLoginState() {
      const { resetUser } = useUserStore()
      // 重置用户
      resetUser()
      // 重置token
      this.resetToken()
    },
    async logout() {
      this.resetLoginState()
    },
    resetToken() {
      this.$reset()
    },
  },
  persist: {
    key: 'lingua-flow_auth',
  },
})
